package com.qianfeng.teachdemo.ui.camera;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.qianfeng.teachdemo.R;
import com.qianfeng.teachdemo.ui.BaseActivity;
import com.qianfeng.teachdemo.utils.FileUtils;

import java.io.File;


/**
 * 主要内容
 * 1.调用系统相机获取bitmap
 * 2.调用系统相机,保存到指定的文件
 * 3.利用gridView保存展示图片,多选,上传选中图片
 */
public class CameraActivity extends BaseActivity {

    private static final int REQUEST_CODE = 111;
    private Button photoBtn, photoBtn1, showBtn;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        imageView = (ImageView) findViewById(R.id.show_photo);
        photoBtn = (Button) this.findViewById(R.id.photo_btn);
        photoBtn1 = (Button) this.findViewById(R.id.photo_btn1);
        showBtn = (Button) this.findViewById(R.id.show_image);
        photoBtn.setOnClickListener(this);
        photoBtn1.setOnClickListener(this);
        showBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.photo_btn:
                // 启动系统相机
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, REQUEST_CODE);
                break;
            case R.id.photo_btn1:
                try {

                    File imageFile = FileUtils.getImageFile();
                    if (null != imageFile) {
                        Uri uri = Uri.fromFile(imageFile);
                        // 启动系统相机
                        Intent intent1 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        intent1.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        startActivity(intent1);
                    }
                } catch (Exception e) {
                    e.printStackTrace();

                }
                break;
            case R.id.show_image:
                startActivity(new Intent(this, ShowImageActivity.class));
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

